﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace AssettDatabase
{
    public partial class Form_Add_Customer : Form
    {
        public Form_Add_Customer()
        {
            InitializeComponent();
        }

        private void Lbl_Supplier_Name_Click(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void textBox8_TextChanged(object sender, EventArgs e)
        {

        }

        private void label11_Click(object sender, EventArgs e)
        {

        }

        private void textBox11_TextChanged(object sender, EventArgs e)
        {

        }

        private void Btn_Return_Main_Click(object sender, EventArgs e)
        {
            this.Dispose();
            FormProvider.MainMenu.Show();
        }

        private void BT_Add_Customer_Click(object sender, EventArgs e)
        {
            try
            {
                if (TB_Customer_Name.Text.Length == 0)
                {
                    MessageBox.Show("Customer Name is a mandatory field.");
                    return;
                }
                if (TB_Customer_ABN.Text.Length == 0)
                {
                    MessageBox.Show("ABN Number is a mandatory field.");
                    return;
                }
                if (TB_Customer_Phone.Text.Length == 0)
                {
                    MessageBox.Show("Customer Phone is a mandatory field.");
                    return;
                }
                if (TB_Primary_Contact_FN.Text.Length == 0)
                {
                    MessageBox.Show("First Name is a mandatory field.");
                    return;
                }
                if (TB_Primary_Contact_LN.Text.Length == 0)
                {
                    MessageBox.Show("Last Name is a mandatory field.");
                    return;
                }
                if (TB_Primary_Contact_Email.Text.Length == 0)
                {
                    MessageBox.Show("Email is a mandatory field.");
                    return;
                }
                if (TB_Accounts_Payable_FN.Text.Length == 0)
                {
                    MessageBox.Show("First Name (Accounts) is a mandatory field.");
                    return;
                }
                if (TB_Accounts_Payable_LN.Text.Length == 0)
                {
                    MessageBox.Show("Last Name (Accounts) is a mandatory field.");
                    return;
                }
                if (TB_Accounts_Payable_Email.Text.Length == 0)
                {
                    MessageBox.Show("Email (Accounts) is a mandatory field.");
                    return;
                }

                BLL.Customer customer = new BLL.Customer();
                if (!customer.Add(TB_Customer_Name.Text, TB_Customer_Phone.Text, TB_Customer_ABN.Text, TB_Customer_mob.Text, TB_Primary_Contact_FN.Text,
                            TB_Primary_Contact_LN.Text, TB_Webstie.Text, TB_Primary_Contact_Email.Text, TB_Accounts_Payable_FN.Text, TB_Accounts_Payable_LN.Text,
                            TB_Accounts_Payable_Email.Text, TB_Customer_Notes.Text))
                    MessageBox.Show("An error occurred during customer insert");
                else
                    MessageBox.Show(TB_Customer_Name.Text + " has been added to the Assett Database");
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void TB_Primary_Contact_Email_TextChanged(object sender, EventArgs e)
        {

        }

        private void TB_Accounts_Payable_FN_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void CB_Account_Pay_AS_Above_CheckedChanged(object sender, EventArgs e)
        {
            if (CB_Account_Pay_AS_Above.Checked)
            {
                TB_Accounts_Payable_FN.Text = TB_Primary_Contact_FN.Text;
                TB_Accounts_Payable_LN.Text = TB_Primary_Contact_LN.Text;
                TB_Accounts_Payable_Email.Text = TB_Primary_Contact_Email.Text;
            }
        }

        private void TB_Customer_Name_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form_Add_Customer_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Dispose();
            FormProvider.MainMenu.Show();
        }
    }
}
